package com.qk.mapper;

import com.qk.dto.UserDto;
import com.qk.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {

    /**
     * 查询用户列表
     */
    List<User> selectList(UserDto userDto);

    /**
     * delete by id
     */
//    @Delete("delete from user where id = #{id}")
    void deleteUserRole(List<Integer> ids);

    /**
     * insert user
     */
    @Insert("insert into user(username,password,name,phone,email,gender,status,dept_id,role_id,image,remark,create_time,update_time) values(#{username},#{password},#{name},#{phone},#{email},#{gender},#{status},#{deptId},#{roleId},#{image},#{remark},#{createTime},#{updateTime})")
    void insert(User user);

    /**
     * select user by id
     */
    @Select("select id, username, password, name, phone, email, gender, status, dept_id, role_id, image, remark, create_time, update_time from user where id = #{id}")
    User selectById(Integer id);

    /**
     *
     * update user
     */
    @Update("update user set username = #{username}, password = #{password}, name = #{name}, phone = #{phone}, email = #{email}, gender = #{gender}, status = #{status}, dept_id = #{deptId}, role_id = #{roleId}, image = #{image}, remark = #{remark}, update_time = #{updateTime} where id = #{id}")
    void update(User user);

    /**
     * select all user
     */
    @Select("select id, username, password, name, phone, email, gender, status, dept_id, role_id, image, remark, create_time, update_time from user")
    List<User> listAll();

    /**
     * select user by role
     */
    List<User> listByRole(String roleLabel);

    /**
     * select user by dept
     */
    List<User> listByDept(Integer deptId);

    /**
     *登录
     */
    @Select(" select u.*,r.label role_label from user u left join role r on u.role_id=r.id where username=#{username}")
    User selectUsername(String username);
}
